#!/bin/sh

# Configuration files server, default is http://ovpnpkg.googlecode.com/svn/trunk
# If you want to deploy ovpnpkg in LAN web server, you can change this to your
# root of ovpnpkg on your web server.
CONFIG_SERVER=

# Use chnroutes, can be yes or no
# If you want to use chnroutes, please change dd-wrt or openwrt DHCP settings
# and set DNS to 8.8.8.8, 8.8.4.4 and 208.67.222.222
USE_CHNROUTES="yes"

# OpenVPN configuration file, please contact your OpenVPN provider
# Please remove any lines of ca, cert, key, up, down
OVPN_CONFIG=""

# Authentication method, can be cert or userpass
AUTHENTICATION_METHOD=cert
#AUTHENTICATION_METHOD=userpass

# If use userpass authentication, fill username and password here
USERNAME=
PASSWORD=

TLS_AUTH_KEY=""

# If use cert authentication, fill ca cert, client cert and client key
CA_CERT=""

CLIENT_CERT=""

CLIENT_KEY=""


########################################################################
# DONT modify anything below unless you know what are you doing
########################################################################

mkdir -p /tmp/openvpn
cd /tmp/openvpn

# Generate files
echo "$OVPN_CONFIG" > openvpn.conf
echo "$CA_CERT"     > ca.crt
echo "$CLIENT_CERT" > client.crt
echo "$CLIENT_KEY"  > client.key
echo "$USERNAME"    > userpass.txt
echo "$PASSWORD"    >>userpass.txt
echo "$TLS_AUTH_KEY"> tls_auth.key

if [ ${#SERVER} -lt 10 ]; then
    CONFIG_SERVER=http://ovpnpkg.googlecode.com/svn/trunk
fi

if [ ! -f "start.sh" ]; then
    wget $CONFIG_SERVER/start.sh
    chmod +x start.sh
fi

export SERVER=$CONFIG_SERVER
./start.sh $AUTHENTICATION_METHOD $USE_CHNROUTES